package net.thxjj.mobileServer.websocket;

import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import net.thxjj.mobileServer.entity.AppRespBean;
import net.thxjj.mobileServer.entity.HeartBean;

import java.util.logging.Logger;

public class UserHeartHandler extends SesstionBaseHandler {
    private Logger log = Logger.getLogger(String.valueOf(this.getClass()));

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame baseBean) throws Exception {

    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        super.channelRead(ctx, msg);
    }

    @Override
    public void chanelReadR(ChannelHandlerContext channelHandlerContext, TextWebSocketFrame s) {
        HeartBean heartBean =  JSONObject.parseObject(s.text(), HeartBean.class);
        AppRespBean appRespBean =  new AppRespBean(heartBean.getMsgId(), ActionType.HEARTBEATRESP.getName(), ErrCode.SUCCESS.getCode(),ErrCode.SUCCESS.getDescription());
        channelHandlerContext.writeAndFlush(new TextWebSocketFrame(appRespBean.toString()));
    }
}
